package se.thoka.twt.client.utils;

import com.google.gwt.user.client.Element;

/**
 * @author Thobias Karlsson, Thoka
 * @since 8 jan 2010
 */
public class JSNIUtil {
	/**
	 * Enables or disables text selection on the supplied element and all of its child nodes.
	 * 
	 * @param enabled Set <code>true</code> to enable text selection.
	 * @param element The element to apply the selection rules to.
	 */
	public native static void setSelectionEnabled(boolean enabled, Element element) /*-{
		if (!enabled)
		{
		    element.onselectstart = function() {
		        return false;
		    };
		    element.unselectable = "on";
		    element.style.MozUserSelect = "none";
			element.style.KhtmlUserSelect = "none";
		    element.style.cursor = "default";
		}
		else
		{
			element.onselectstart = null;
			element.unselectable = null;
			element.style.MozUserSelect = null;
			element.style.KhtmlUserSelect = null;
		}
	}-*/;

	/**
	 * Redirects the page to another URL.
	 * 
	 * @param url The URL to redirect to.
	 */
	public static native void redirectPage(String url)/*-{
			$wnd.location = url;
		}-*/;

	/**
	 * Reloads the page.
	 */
	public static native void reloadPage()/*-{
			$wnd.location.reload();
		}-*/;
}
